package com.gxa.ehome.controller;

import com.gxa.ehome.pojo.SysUser;
import io.swagger.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

//Restful风格的请求方式

@Controller
@RequestMapping(value = "/sysUser2"/*,method = {RequestMethod.POST,RequestMethod.GET}*/)
@Api(value = "描述restful风格的控制器",tags="restfulController")
public class RestfulController {

    //查询全部用户信息
    @GetMapping
    @ApiOperation(value = "查询全部系统用户信息", notes="使用restful风格中,查询全部用户信息的操作方式,不带参数",tags = "getAll",response=List.class,httpMethod = "GET")
    public List<SysUser> getAll(){
        System.out.println("GET/ehome/sysUser2/");
        return null;
    }

    //查询指定id用户信息
    @GetMapping("/{id}")
    @ApiOperation(value = "通过id获取SysUser对象的方法",response = SysUser.class,httpMethod = "GEt")
    @ApiImplicitParam(value = "用户id",required = true,paramType = "Integer",example = "1")
    public SysUser getById(@PathVariable("id")Integer id){
        System.out.println("id");
        return null;
    }
    //分页查询
    @GetMapping("/page/{page}/limit/{limit}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",required = true,paramType = "Integer"),
            @ApiImplicitParam(name = "limit",required = true,paramType = "Integer")

    })
    public SysUser getByPage(@PathVariable("page")Integer page,@PathVariable("limit")Integer limit){
        System.out.println("Get/page/{page}/limit/{limit}");
        System.out.println(page);
        System.out.println(limit);
        return null;
    }
    //前端获取数据注入到SysUser对象上
    @PostMapping

    public Boolean reg(@RequestBody @ApiParam(name = "sysUser",required = true,type = "SysUser") SysUser sysUser){
        System.out.println("Post/ehome/sysUser2");
        System.out.println("jobNumber"+sysUser.getJobNumber());
        return false;
    }
    //前端获取的数据注入到map上(适合操作复杂数据类型:多表生成一个对象)
   /* @PostMapping
    public Boolean reg2(@RequestBody Map<String,Object> objectMap){
        System.out.println("Post/ehome/sysUser2");
        System.out.println("jobNumber"+objectMap.get("jobNumber"));
        return false;
    }*/

    //修改SysUser对象的信息
    @PutMapping
    public void edit(@RequestBody SysUser sysUser){
        System.out.println("PUT/ehome/sysUser2");
        System.out.println("jobNumber"+sysUser.getJobNumber());
        System.out.println("id"+sysUser.getId());
        return ;
    }

    //根据ID删除
    @DeleteMapping("/id/{id}")
    public void delete(@PathVariable("id")Integer id){
        System.out.println("DELETE/ehome/sysUser2");
        System.out.println("id"+id);
    }

   }
